home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / gfx / edit / AmiCAD_2.07.lha / AmiCAD / ARexx / TableVérité.AmiCAD < prev    next >
Text File  |  2000-11-11  |  4KB  |  145 lines

  1. /* Création d'une table de vérité.
  2.    Version 1.00: 4 Avril 1998 © R.Florac
  3.    Version 1.01: 11 Novembre 2000 (localisation anglais/français)
  4.    $VER: TableVérité.AmiCAD 1.01 (11 Novembre 2000, © R.Florac) */
  5.  
  6. options results     /* indispensable pour récupérer le résultat des macros */
  7.  
  8. signal on error     /* pour l'interception des erreurs */
  9. signal on syntax
  10.  
  11. 'LANGUAGE'
  12. if result="français.language" then fr=1
  13. else fr=0
  14.  
  15. if fr=1 then 'ASKNUM("Nombre d''entrées",2)'
  16. else 'ASKNUM("Number of inputs",2)'
  17. nbe=result
  18. if nbe="" then exit
  19.  
  20. l=0
  21. do i=1 to nbe
  22.     if fr=1 then 'ASKTEXT("Nom de l''entrée 'i'","E")'
  23.     else 'ASKTEXT("Name of input 'i'","E")'
  24.     nomE.i=result
  25.     'TXWIDTH("'nomE.i'")'; lc=result
  26.     if lc>l then l=lc
  27. end
  28.  
  29. if fr=1 then 'ASKNUM("Nombre de sorties",2)'
  30. else 'ASKNUM("Number of outputs",2)'
  31. nbs=result
  32. if nbs="" then exit
  33.  
  34. do i=1 to nbs
  35.     if fr=1 then 'ASKTEXT("Nom de la sortie 'i'","Q")'
  36.     else 'ASKTEXT("Name of output 'i'","Q")'
  37.     nomS.i=result
  38.     'TXWIDTH("'nomS.i'")'; lc=result
  39.     if lc>l then l=lc
  40. end
  41.  
  42. 'SETSCALE(0,100,100):ROTATE(0,0):SYMMETRY(0,0):DRAWMODE(1)'
  43.  
  44. nbl=2**nbe    /* nombre de lignes */
  45.  
  46. l=l+20
  47. do i=1 to nbe
  48.     cole.i=10+l*i
  49.     '(TXWIDTH("'nomE.i'")-TXWIDTH("0"))/2'
  50.     'MARK(WRITE("'nomE.i'", 'cole.i-result', 20))'
  51. end
  52.  
  53. do i=1 to nbs
  54.     cols.i=10+l*(i+nbe)
  55.     '(TXWIDTH("'nomS.i'")-TXWIDTH("0"))/2'
  56.     'MARK(WRITE("'nomS.i'", 'cols.i-result', 20))'
  57. end
  58.  
  59. do c=1 to nbe
  60.     ng=2**c
  61.     ligne=1
  62.     do i=1 to ng/2
  63.     do j=1 to nbl/ng
  64.         'MARK(WRITE("0", 'cole.c', 20+'ligne'*15))'
  65.         val.c.ligne=0
  66.         ligne=ligne+1
  67.     end
  68.     do j=j to nbl/ng*2
  69.         'MARK(WRITE("1", 'cole.c', 20+'ligne'*15))'
  70.         val.c.ligne=1
  71.         ligne=ligne+1
  72.     end
  73.     end
  74. end
  75.  
  76. /* Tracé des lignes verticales */
  77. col=cole.1-l%2+5
  78. do c=1 to nbe+nbs+1
  79.     select
  80.     when c=1 then 'DRAWMODE(2)'
  81.     when c=nbe+1 then 'DRAWMODE(2)'
  82.     when c=nbe+nbs+1 then 'DRAWMODE(2)'
  83.     otherwise 'DRAWMODE(1)'
  84.     end
  85.     'MARK(DRAW('col',8,'col',23+'nbl'*15))'
  86.     col=col+l
  87. end
  88.  
  89. /* Tracé des lignes horizontales */
  90. ligne=8
  91. do i=1 to nbl+2
  92.     select
  93.     when i=1 then 'DRAWMODE(2)'
  94.     when i=2 then 'DRAWMODE(2)'
  95.     when i=nbl+2 then 'DRAWMODE(2)'
  96.     otherwise 'DRAWMODE(1)'
  97.     end
  98.     'MARK(DRAW('cole.1-l%2+5','ligne','col-l','ligne'))'
  99.     ligne=ligne+15
  100. end
  101.  
  102. /* Remplissage éventuel de la table */
  103. if fr=1 then 'DRAWMODE(1):REQUEST("Voulez-vous remplir la table?")'
  104. else 'DRAWMODE(1):REQUEST("Do-you want to fill the table?")'
  105. if result=1 then do
  106.     'DEF OR(A,B)=IF(A+B,1,0)'
  107.     'DEF AND(A,B)=IF(A*B,1,0)'
  108.     'DEF NOT(A)=IF(A,0,1)'
  109.     'DEF NAND(A,B)=NOT(AND(A,B))'
  110.     'DEF NOR(A,B)=NOT(OR(A,B))'
  111.     'DEF XOR(A,B)=IF(A+B==1,1,0)'
  112.     do i=1 to nbs
  113.     if fr=1 then do
  114.  'ASKTEXT("Équation de 'nomS.i'?"+CHR(10)+"Vous pouvez utiliser les"+CHR(10)+"fonctions NOT(A),"+CHR(10)+"AND(A,B), OR(A,B), XOR(A,B)"+CHR(10)+"NAND(A,B) et NOR(A,B)."+CHR(10)+"Utilisez les noms des variables"+CHR(10)+"tels que vous les avez donnés.","")'
  115.     end
  116.     else do
  117.  'ASKTEXT("Equation of 'nomS.i'?"+CHR(10)+"You can use the"+CHR(10)+"functions NOT(A),"+CHR(10)+"AND(A,B), OR(A,B), XOR(A,B)"+CHR(10)+"NAND(A,B) et NOR(A,B)."+CHR(10)+"Use the names of variables"+CHR(10)+"as you entered them.","")'
  118.     end
  119.     eq=result
  120.     if eq~= "" then do
  121.         do ligne=1 to nbl
  122.         do j=1 to nbe
  123.             'EXEC("'nomE.j'='val.j.ligne'")'
  124.         end
  125.         'EXEC("'eq'")'; r=result
  126.         'MARK(WRITE("'r'",'cols.i','20+ligne*15'))'
  127.         end
  128.     end
  129.     end
  130. end
  131.  
  132. exit
  133.  
  134. /* Traitement des erreurs, interruption du programme */
  135. syntax:
  136. erreur=RC
  137. if fr=1 then 'MESSAGE("Script TableVérité.AmiCAD"+CHR(10)+"Erreur de syntaxe"+CHR(10)+"en ligne 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  138. else 'MESSAGE("TableVérité.AmiCAD script"+CHR(10)+"Syntax error"+CHR(10)+"in lige 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  139. exit
  140.  
  141. error:
  142. if fr=1 then 'MESSAGE("Script TableVérité"+CHR(10)+"Erreur en ligne 'SIGL'")'
  143. else 'MESSAGE("TableVérité.AmiCAD script"+CHR(10)+"Error in line 'SIGL'")'
  144. exit
  145.